home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / coder / ieeereal.sml < prev    next >
Encoding:
Text File  |  1993-01-27  |  826 b   |  27 lines

  1. (* Copyright 1989 by AT&T Bell Laboratories *)
  2. (* Support for IEEE floating-point constants
  3.  * Double precision format (for normalized numbers):
  4.  *   Bias = 1023.
  5.  *   Exponent = 11 bits.
  6.  *   Range of exponent = [1..2046]
  7.  *   Mantissa = 52 (+1) bits.
  8.  *   Value = (-1)^s * 2^(e-1023) * 1.f
  9.  *)
  10. structure IEEEReal = RealConst(
  11. struct
  12.     val significant = 53 (* 52 + redundant 1 bit *)
  13.     val minexp = ~1021 and  maxexp = 1024
  14.     open Bits
  15.     fun transreal (sign, frac, exp) =
  16.      if frac(0,1)=0 then "\000\000\000\000\000\000\000\000"
  17.           else implode[chr(orb(lshift(sign,7),rshift(exp+1022,4))),
  18.                chr(andb(255,orb(lshift(exp+1022,4),frac(1,4)))),
  19.                chr(frac(5,8)),
  20.                chr(frac(13,8)),
  21.                chr(frac(21,8)),
  22.                chr(frac(29,8)),
  23.                chr(frac(37,8)),
  24.                chr(frac(45,8))]
  25.  
  26. end)
  27.